<?php
require_once './model/db.php';
require_once './model/products.php';
require_once './model/categories.php';
require_once './model/myfunctions.php';
$fc= new MyFunctions();
$obj_products= new Products();
$obj_category= new Categories();
$cat_on_tops = array(
    1 => CAT_ON_TOP_1,
    2 => CAT_ON_TOP_2,
    3 => CAT_ON_TOP_3
);
?>
<div id="cols3" class="box">

    <!-- Column I. -->
    <?php for($i=1;$i<=3;$i++):?>
    <?php 
    $category= $obj_category->get_name_by($cat_on_tops[$i]);
    $params=array('id_cat'=>$cat_on_tops[$i]);
    $products=$obj_products->get_product_by($cat_on_tops[$i]);
    $is_first_item=true;
    ?>
    <div class="col <?php if($i===3) {echo "last";}?>">

        <h3><a href="#" style="text-decoration: none;"><?php if(!empty($category)){echo $category['name'];} else {echo "<i>Empty data, try again later!</i>"; };?></a></h3>
        <div class="itemp-product">

            <p class="nom t-center"><a href="detail.php?type=p&id=<?php echo $products[0]['id'];?>" ><img src="<?php echo PATH_PRODUCTS_IMAGE.$products[0]['thumb'];?>" alt="" style="max-height: 255px;max-width: 255px;"></a></p>

            <div class="col-text">
                <span style="
                      font-weight: bold;
                      "><a href="detail.php?type=p&id=<?php echo $products[0]['id'];?>" style="text-decoration: none;"><?php echo $fc->charLimit($products[0]['name'],50);?></a></span>

                <p><?php echo $fc->charLimit($products[0]['overview'],170);
                if(empty($products)) {echo "<i>Empty data, try again later!</i>";}?></p>

                <ul class="ul-01">
                    <?php foreach ($products as $product):?>
                    <?php if($is_first_item)
                    {
                        $is_first_item=FALSE;
                        continue;
                    }
                        ?>
                    <li><a href="detail.php?type=p&id=<?php echo $product['id'];?>" style="text-decoration: none;"><?php echo $product['name'];?></a></li>
                    <?php endforeach;?>
                </ul></div> <!-- /col-text -->

                <div class="col-more"><a href="<?php if(empty($category)){echo "#";} else {echo "list.php?type=p&id_cat=".$category['id'];} ?>"><img src="<?php echo PATH_DESIGN_IMAGE;?>cols3-more.gif" alt=""></a></div>
        </div>
    </div> <!-- /col -->
<?php endfor;?>
    <hr class="noscreen"></div>